#pragma once
#include "WceUiLayer.h"

enum E_ILAYER_TYPE
{
	E_ILAYER_TYPE_H = 1,
	E_ILAYER_TYPE_V,
};
enum E_ILAYER_DIRECTION
{
	E_D_ILAYER_LEFT = 1,
	E_D_ILAYER_RIGHT,
	E_D_ILAYER_UP,
	E_D_ILAYER_DOWN,
};

class CWEILayer : public CWceUiLayer
{
	WCEUI_DYNCREATE_BEGIN(CWEILayer, CWceUiLayer)
public:
	CWEILayer(void);
	virtual ~CWEILayer(void);

	virtual void SetProperties(PCWceUiXmlElem pCreateElem);
	virtual void OnInitLayer();

	virtual void OnLButtonDown(UINT nFlags, POINT point);
	virtual void OnMouseMove(UINT nFlags, POINT point);
	virtual void OnLButtonUp(UINT nFlags, POINT point);
	virtual void OnLoseCapture();
	virtual void OnTimer(WORD wIDEvent);

	virtual void OnCmdDown();		//down cmd
	virtual void OnCmdEndDown();	//end down cmd
	virtual void OnIClick(CWceUiLayer* pLayer);

	virtual void OnStyleDown(CWceUiLayer* pLayer);
	virtual void OnStyleEndDown(CWceUiLayer* pLayer);

	virtual void OnLayerMoved();


	void SetVisualRectAndType(LPCRECT lpRect, E_ILAYER_TYPE type);
	E_ILAYER_TYPE GetVisualRectAndType(LPRECT lpRect) const;

	void SetSlideSpeed(int nFast, int nNormal, int nSlow);
	void GetSlideSpeed(int& nFast, int& nNormal, int& nSlow) const;

	void SetSlideFrequence(int nFreq);
	void SetBlockSlide(BOOL bBlockSlide);

protected:
	//return TRUE for continue slide, FALSE for end slide
	BOOL DoSliding();
	void StopSliding();
	void OnMove(CPoint pt);
	void GetHLimit(int& nMinX, int& nMaxX);
	void GetVLimit(int& nMinY, int& nMaxY);
	void OnEndMove();
	BOOL CanSlide();

private:
	enum E_ILAYER_STATUS
	{
		E_ILAYER_UNINIT = 1,
		E_ILAYER_DOWN,
		E_ILAYER_MOVE,
		E_ILAYER_SLIDE,
	};
	E_ILAYER_STATUS m_status;
	CRect			m_rcVisual;		//the visual rect
	E_ILAYER_TYPE   m_type;

	CPoint		m_downPoint;		//the mouse position of mouse down
	CPoint		m_lastPoint;

	BOOL		m_bCmdDownSended;	//down cmd is sended
	void		SendEndDownCmd();

	CWceUiLayer* m_pDownLayer; 
	DWORD		 m_dwBeforeSliderTick;
	int			 m_nCurFame;
	E_ILAYER_DIRECTION m_direction;
	int			 m_nSlideDstLeft;
	int			 m_nSlideDstTop;
	int			 m_nTotalDist;
	CRect		 m_rcBeforeSlide;
	int			 m_nTotalFrame;
	BOOL		 m_bSetBeforeSliderTick;

	int			m_nFast;
	int			m_nNormal;
	int			m_nSlow;
	int			m_nPage;
	int			m_nFreq;
	DWORD		m_dwLastSlideTick;
	BOOL		m_bBlockSlide;
};
WCEUI_DYNCREATE_END(CWEILayer, CWceUiLayer)
